package com.ygkj.demo


import org.junit.Test
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        //  assertEquals(4, 2 + 2)
        var startdate = " 02:25"
        var enddate = " 18:25"
        val s3 = SimpleDateFormat("yyyy-MM-dd")
        var format = s3.format(Date())
        val s2 = SimpleDateFormat("HH:mm")
        val s1 = SimpleDateFormat("yyyy-MM-dd HH:mm")
        var parse1 = s1.parse(format + startdate)
        var parse2 = s1.parse(format + enddate)

        println(parse1.time)

        var effectiveDate = isEffectiveDate(Date(), parse1, parse2)
        println("$effectiveDate")
    }

    fun isEffectiveDate(nowTime: Date, startTime: Date, endTime: Date): Boolean {
//        nowTime.time.
        if (startTime.time == nowTime.time || nowTime.time == endTime.time) {
            return true
        }
        val date = Calendar.getInstance()
        date.time = nowTime
        val begin = Calendar.getInstance()
        begin.time = startTime
        val end = Calendar.getInstance()
        end.time = endTime
        return date.after(begin) && date.before(end)
    }

    @Test
    fun test() {
        var list = ArrayList<String>()
        list.add("1")
        list.add("2")
        var list2 = ArrayList<String>()
        list2.add("3")
        list2.add("4")

        var list3 = ArrayList<String>()
        list3.addAll(list2)
        list3.addAll(list)
        list.clear()
        list.addAll(list3)
        list.forEach { it ->
            println(it)
        }
    }

    @Test
    fun test1() {
//        var str = String(Base64.decode("你好加密文件".toByteArray(), Base64.DEFAULT))
//        var decode = Base64.getDecoder().decode("你好加密文件".toByteArray(), "123".toByteArray())
        var encodeToString = Base64.getEncoder().encodeToString("你好".toByteArray())
        print(encodeToString)
    }

    @Test
    fun test2() {
        val de1 = EncrypAES()
        val json =
            "DbNh0t52tlesTxzxNUUNP1WfOYVYmRt/OBIzljjdWuIw9hOIiqfMQsRJm+bSvsSCVx+t3GFRfy1l+/5HHMURfwhI2ixd1j7YdlCs0hfROoc="
        de1.init()
        var decode = Base64.getDecoder().decode(json) //解码
//        var encode1 = Base64.getEncoder().encode(json.toByteArray())//编码
//        var encode = Base64.getEncoder().encode(decode)

        var encrytor = de1.Encrytor(json)
        val decontent = de1.Decryptor(decode)
//        println("加密后:" + String(encrytor))
        println("解密后:" + String(decontent))

    }

    @Test
    fun test3() {
    var str = "你好"
        var encode = Base64.getEncoder().encodeToString(str.toByteArray())
        println(encode)
        var decode = Base64.getDecoder().decode(encode)
        print(String(decode))


    }

    @Test
    fun  text(){


    }

}